package com.gxa.service.impl.system;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.mapper.system.RoleMapper;
import com.gxa.pojo.entity.system.Role;
import com.gxa.service.system.RoleService;
import com.gxa.utils.QueryResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lch
 * @Date 2024/2/22 15:52
 * @Description 员工管理
 **/
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public int addRole(Role role) {
        if (role.getName() == null || role.getName().equals("")) {
            return -1;
        }
        return roleMapper.insert(role);
    }

    @Override
    public Integer updateRole(Role role) {
        if (role.getName() == null || role.getName().equals("")) {
            return -1;
        }
        return roleMapper.update(role);
    }

    @Override
    public Integer deleteRoleById(Integer id) {

        return roleMapper.delete(id);
    }

    @Override
    public QueryResult queryAllRole(Role role) {
        //分页查询
        Page<Role> page = PageHelper.startPage(role.getPage(), role.getLimit());

        List<Role> roleList = roleMapper.query(role);

        QueryResult queryResult = new QueryResult();
        queryResult.setData(roleList);
        queryResult.setCount(page.getTotal());
        return queryResult;
    }
}
